public class AppCacheManifestTransformer extends ResourceTransformerSupport
ResourceTransformer
implementation that helps handling resources
within HTML5 AppCache manifests for HTML5 offline applications.
This transformer:
ResourceResolver
strategies
All files that have the ".appcache" file extension, or the extension given in the constructor, will be transformed by this class. This hash is computed using the content of the appcache manifest and the content of the linked resources; so changing a resource linked in the manifest or the manifest itself should invalidate the browser cache.
In order to serve manifest files with the proper "text/manifest"
content type,
it is required to configure it with
contentNegotiationConfigurer.mediaType("appcache", MediaType.valueOf("text/manifest")
in a WebMvcConfigurer
.
Modifier and Type | Class and Description |
---|---|
private static class |
AppCacheManifestTransformer.LineAggregator |
private static class |
AppCacheManifestTransformer.LineInfo |
private static class |
AppCacheManifestTransformer.LineOutput |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
CACHE_HEADER |
private static java.nio.charset.Charset |
DEFAULT_CHARSET |
private java.lang.String |
fileExtension |
private static Log |
logger |
private static java.lang.String |
MANIFEST_HEADER |
private static java.util.Collection<java.lang.String> |
MANIFEST_SECTION_HEADERS |
Constructor and Description |
---|
AppCacheManifestTransformer()
Create an AppCacheResourceTransformer that transforms files with extension ".appcache".
|
AppCacheManifestTransformer(java.lang.String fileExtension)
Create an AppCacheResourceTransformer that transforms files with the extension
given as a parameter.
|
Modifier and Type | Method and Description |
---|---|
private static byte[] |
getResourceBytes(Resource resource) |
private AppCacheManifestTransformer.LineOutput |
processLine(AppCacheManifestTransformer.LineInfo info,
HttpServletRequest request,
Resource resource,
ResourceTransformerChain transformerChain) |
Resource |
transform(HttpServletRequest request,
Resource resource,
ResourceTransformerChain chain)
Transform the given resource.
|
getResourceUrlProvider, resolveUrlPath, setResourceUrlProvider, toAbsolutePath
private static final java.util.Collection<java.lang.String> MANIFEST_SECTION_HEADERS
private static final java.lang.String MANIFEST_HEADER
private static final java.lang.String CACHE_HEADER
private static final java.nio.charset.Charset DEFAULT_CHARSET
private static final Log logger
private final java.lang.String fileExtension
public AppCacheManifestTransformer()
public AppCacheManifestTransformer(java.lang.String fileExtension)
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain chain) throws java.io.IOException
ResourceTransformer
request
- the current requestresource
- the resource to transformchain
- the chain of remaining transformers to delegate tonull
)java.io.IOException
- if the transformation failsprivate static byte[] getResourceBytes(Resource resource) throws java.io.IOException
java.io.IOException
private AppCacheManifestTransformer.LineOutput processLine(AppCacheManifestTransformer.LineInfo info, HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain)